using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BuddhistSchools.DTO.Models.Mapping
{
    public class SchoolClassMap : EntityTypeConfiguration<SchoolClass>
    {
        public SchoolClassMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("SchoolClass");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.CourseID).HasColumnName("CourseID");

            // Relationships
            this.HasMany(t => t.Term_Subject)
                .WithMany(t => t.SchoolClasses)
                .Map(m =>
                    {
                        m.ToTable("SchoolClass_Term_Subject");
                        m.MapLeftKey("SchoolClassID");
                        m.MapRightKey("Term_SubjectID");
                    });

            this.HasRequired(t => t.Course)
                .WithMany(t => t.SchoolClasses)
                .HasForeignKey(d => d.CourseID);

        }
    }
}
